package test;

import java.util.ArrayDeque;
import java.util.Deque;

/**
 * @ClassName T5
 * @Description
 * @Author Jingxiao.Ye
 * @Date 2021/8/8 下午6:07
 * @Version V1.0
 * @Since JDK 11
 */
public class T5 {

    public static void main(String[] args) {

    }

    public static int[] dailyTemperatures(int[] T) {
        int[] res = new int[T.length];
        Deque<Integer> deque = new ArrayDeque<>();
        for (int i = 0; i < T.length; i++) {
            while (deque.peekLast()!=null && T[deque.peekLast()] < T[i]){
                Integer index = deque.pollLast();
                res[index] = i-index;
            }
            deque.offerLast(i);
        }
        while (!deque.isEmpty()){
            Integer index = deque.pollLast();
            res[index] = 0;
        }
        return res;
    }
}
